Next | Prev | Up | Top | Contents | Index

Initializing Asynchronous I/O

You can initialize asynchronous I/O in either of two ways. One way is simple; the other gives you control over the initialization.


Implicit Initialization

You can initialize asynchronous I/O simply by starting an operation with aio_read(), lio_listio(), or aio_write(). The first such call causes default initialization. This is the only form of initialization described by the POSIX standard. However, in a real-time program you often need to control at least the timing of initialization.


Initializing with aio_sgi_init()

You can take greater control of asynchronous I/O by calling aio_sgi_init() (refer to the aio_sgi_init(3) reference page and to the declarations in /usr/include/aio.h). The argument to this call can be a null pointer, indicating you want default values, or you can pass an aioinit_t structure. The principal fields of this structure specify

Other fields of the aioinit_t structure such as aio_num and aio_usedba are not used at this time and must be zero. Zero-valued fields are taken as a request for the default for that field. Example 8-1 shows a subroutine to initialize asynchronous I/O, given counts of devices and calling processes.

Example 8-1 : Initializing Asynchronous I/O

int initAIO(int numDevs, int numSprocs, int maxOps)
{

aioinit_t A = {0}; /* ensure zero'd fields */

if (numDevs) /* we do know how many devices */

A.aio_threads = 1+numDevs;

if (numSprocs) /* we do know how many sprocs */

A.aio_locks = A.aio_numusers = 1+numSprocs;

if (maxOps) /* we do know max aiocbs at 1 time */

A.aio_num = maxOps;

return aioinit(&A);

}

When to Initialize

The time at which initialization occurs is important. If you initialize in a process that has been assigned to run on an isolated CPU, the asynchronous I/O processes will also run on that CPU. You probably want the I/O processes to run under normal dispatching on unrestricted CPUs. In that case, the proper sequence of initialization is:

The asynchronous I/O processes created by aioinit() continue to be scheduled according to their priority in whatever CPUs remain available.


Next | Prev | Up | Top | Contents | Index